<template>
	<div>
		<div class="dv_img">
			<img :src="myuser.user_img" alt="" v-if="myuser && myuser.user_img" />
			<img src="../../assets/default_img.jpg" alt="" v-else />
			<input type="text" placeholder="说点什么吧" v-model="comcontent" ref="postipt" />
			<button @click="commentpublic">发送</button>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			myuser: null,
			comcontent: ''
		};
	},
	methods: {
		// 获取自己的信息
		async myUserInfo() {
			const res = await this.$http.get('/user/' + localStorage.getItem('id'));
			// console.log(res)
			this.myuser = res.data[0];
		},
		commentpublic() {
			if (!this.myuser && !localStorage.getItem('id') && !localStorage.getItem('token')) {
				this.$msg.fail('请先登录');
				return;
			}
			this.$emit('postcomment', this.comcontent);
			this.comcontent = '';
			// this.$msg("发表成功")
		},
		focusIpt() {
			this.$refs.postipt.focus();
		}
	},
	created() {
		if (localStorage.getItem('token')) {
			this.myUserInfo();
		}
	},
	props: ['datalength']
};
</script>

<style lang="less">
.dv_img {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-top: 10px;
	font-size: 14px;
	img {
		width: 30px;
		height: 30px;
		border-radius: 50%;
		margin-left: 12px;
	}
	input {
		outline: none;
		border: none;
		background-color: #efefef;
		border-radius: 4.167vw;
		padding: 8px 10px;
		box-shadow: 0 0 1px rgba(0, 0, 0, 0.15);
		margin-right: 2.778vw;
		width: 216px;
	}
	button {
		outline: none;
		border: none;
		background: #fb7299;
		line-height: 7.222vw;
		padding: 0.556vw 2.778vw 0 2.778vw;
		height: 7.222vw;
		border-radius: 3.611vw;
		color: white;
		margin-right: 20px;
	}
}
</style>
